<?php

require_once __DIR__ . '/vendor/autoload.php';
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;

/*链接到amqp服务器*/
$connection = new AMQPStreamConnection('127.0.0.1', 5672, 'myuser', 'mypass');

/*打开队列，指定名称hello*/
$channel = $connection->channel();

/*
    name: $queue 队列的名称
    passive: 
    durable: 
    exclusive: 单独的
    auto_delete: 自动删除
*/
$channel->queue_declare('hello', false, false, false, false);

echo ' [*] Send messages. To exit press CTRL+C', "\n";

/*ampq消息*/
while (1) {
	/*消息*/
    $msg = new AMQPMessage('Hello World!' . time());

    /*推送*/
    $channel->basic_publish($msg, '', 'hello');

    echo " [x] Sent 'Hello World!'\n";

    usleep(500);
}

$channel->close();
$connection->close();
